/**
 * 
 */
package com.taobao.service;

import java.util.Map;

import com.taobao.api.direct.TaobaoDirectJsonRestClient;

/**
 * Provides services about session
 * 
 * @author hujingfei.pt@taobao.com
 *
 */
public interface SessionService {

	public final static String SESSION = "SESSION";
	public final static String NAME = "NAME";
	/**
	 * Get the session of the user
	 * 
	 * @param userName the user name
	 * @param password the user password
	 * @return the session id(key)
	 * @throws Exception when some services behind back-end is unavailable, throw exceptions
	 */
	public String getSession(String userName, String password) throws Exception;
	
	/**
	 * Return the session id(key)
	 * 
	 * @return if there is a session key in the session object, return it, or return null
	 */
	public String getSession();
	
	/**
	 * Return the login name of the user 
	 * 
	 * @return if there is a login name in the session object, return it, or return null
	 */
	public String getLoginName();
	
	/**
	 * Passing several essential parameters to the back-end. 
	 * 
	 * @param url the url used to access the TOP api.
	 * @param app the key of the application.
	 * @param secrt the password of the application.
	 * @param loginAddress the url used to login.
	 * @return if initialized successfully, return true, or return false.
	 * @throws Exception when some services behind back-end is unavailable, throw exceptions.
	 */
	public boolean init(String url, String app, String secrt, String loginAddress) throws Exception;
	
	/**
	 * Return the client object
	 * 
	 * @return the client object
	 */
	public TaobaoDirectJsonRestClient getClient();
	
	/**
	 * Store the session and the name.
	 * 
	 * @param session the session 
	 * @param name the login name of the user
	 * @return the name of the user
	 */
	public String setSession(String session,String name);
	
	/**
	 * Get the url for the login
	 * 
	 * @param domain 
	 * @param url
	 * @return the url used to login
	 */
	public String getLoginURL(String domain, String url);	
	
	/**
	 * Get the url used to access the TOP
	 * 
	 * @param params the parameters pairs
	 * @return the url used to access the TOP
	 */
	public String getUrl(Map<String,String> params);
	
	/**
	 * The user logouts.
	 * 
	 * @param domain 
	 * @param url
	 * @return
	 */
	public String logout(String domain,String url);
}
